﻿using System;
using System.Collections.Generic;
using System.Text;
using MDAControlsFramework;
using Microsoft.WindowsMobile.PocketOutlook;
using MDAControlsFramework.Helpers;

namespace MDACalendar {
	/// <summary>
	/// seznam událostí daneho dne
	/// </summary>
	class ControlDayListAppointments: MDAContainer {
		private DateTime _date;
		private ControlDayListAppointment _mainData;

		public override bool AddObject(IMDAObject mdaObject) {
			// pokud je prvek obsahem (není nastavením)
			ControlDayListAppointment control = mdaObject as ControlDayListAppointment;
			if (control != null) {
				_mainData = control;
				return true;
			}

			return base.AddObject(mdaObject);
		}

		public override void Initialize() {
			if (_name == string.Empty) {
				_name = "DayListAppintments";
			}
			base.Initialize();
			SetDataChangeEvent(this, "DayList", SetDate);
		}

		public void SetDate(object sender, MDADataChangeArgs e) {
			_date = Settings.GetDateTime(e.NewValue);
			List<Appointment> list = Settings.GetAppointments(_date, _date.AddDays(1));
			for (int i = 0; i < list.Count; i++) {
				ControlDayListAppointment data = _mainData.Clone() as ControlDayListAppointment;
				data.Appointment = list[i];
				_controls.Add(data);
			}
			this.Invalidate();
		}
	}
}
